#!/usr/sbin/rsct/perl5/bin/perl
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
#  
#  
# Licensed Materials - Property of IBM 
#  
# (C) COPYRIGHT International Business Machines Corp. 2000,2004 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 

# Send a message to the console of a particular user about an ERRM event
# that occurred.

# @(#)33   1.3   src/rsct/rm/ER/msgevent.perl, ERrm, rsct_rzauh, rzauh0431a 9/3/02 15:28:34

use strict;
use Getopt::Std;
use POSIX qw(strftime);

sub usage {
#------------------------- Put Print Text Up To Here ------------------------->|
print <<ENDOFUSAGETEXT;
Usage:  msgevent [-h] user [tty]
          -h        Display this usage information.
ENDOFUSAGETEXT
exit 1; }

# Parse the cmd line args and check them
if (! getopts('h') ) { &usage; }
if (scalar(@ARGV) < 1 || $::opt_h) { &usage; }

my $where = join(' ', @ARGV);
my ($eventSec,$junk) = split( /,/,$ENV{ERRM_TIME} );
my $convertedTime = strftime("%A %D %T", localtime($eventSec) );
my $str = "$ENV{ERRM_COND_SEVERITY} $ENV{ERRM_TYPE} occurred:\n  Condition:  $ENV{ERRM_COND_NAME}\n  Node:  $ENV{ERRM_NODE_NAME}\n  Resource:  $ENV{ERRM_RSRC_NAME}\n  Resource Class:  $ENV{ERRM_RSRC_CLASS_NAME}\n  Resource Attribute: $ENV{ERRM_ATTR_NAME}\n  Attribute Type: $ENV{ERRM_DATA_TYPE}\n  Attribute Value: $ENV{ERRM_VALUE}\n  Time: $convertedTime\n";

my $rc = system(qq(echo "$str" | write $where)) >> 8;

exit $rc;
